#include "qtips.h"

#include <QPainter>

#define ICON_OK ":/res/ok.png"
#define ICON_ERR ":/res/error.png"

QTips::QTips(QWidget *parent) : QWidget(parent)
{

}

QString QTips::getContent() const
{
    return this->content;
}

void QTips::setContent(const QString content)
{
    this->content=content;
    repaint();
}

bool QTips::getState() const
{
    return this->state;
}

void QTips::setState(const bool state)
{
    this->state=state;
    repaint();
}

void QTips::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter{this};
    QRect rect(0,0,width(),height());
    painter.setViewport(rect);
    painter.setRenderHints(QPainter::Antialiasing|QPainter::SmoothPixmapTransform);

    QPen pen;
    pen.setWidth(1);
    pen.setColor((this->state)?Qt::darkGreen:Qt::red);
    pen.setStyle(Qt::SolidLine);
    painter.setPen(pen);

    QBrush brush;
    brush.setColor(Qt::transparent);
    brush.setStyle(Qt::SolidPattern);


//    painter.drawRect(rect);
    painter.drawRoundedRect(rect,8,8);
    painter.drawText(35,height()/2+5,content);
    painter.drawImage(QRect{5,4,24,24},QImage{(this->state)?ICON_OK:ICON_ERR});

}
